/*
 * @Description: description
 * @Author: yucs
 * @Date: 2023-03-13 17:30:05
 * @LastEditTime: 2023-04-27 17:18:07
 * @LastEditors: Please set LastEditors
 */
export default {
    data () {
        return {
          search: {
            pageNo: 1,
            pageSize: 20,
            needTotal: true
          },
          pageOption: {
            pageSize: 20,
            current: 1,
            total: 1,
            showSizeChanger: true,
            pageSizeOptions: ['20', '50', '100'],
            showQuickJumper: true,
            showTotal: (total, range) => this.$t('分页总条数', { total: this.pageOption.total, current: this.pageOption.current, pages: Math.ceil(this.pageOption.total / this.pageOption.pageSize) })
          }
        }
      },
      mounted() {
        this.pageOption.pageSize = this.search.pageSize;
        this.pageOption.pageNo = this.search.pageNo;
      },
      methods: {
        handleTableChange (pagination, filters, sorter) {
          if (pagination.pageSize != this.search.pageSize) {
            this.search.pageNo = 1
            this.search.pageSize = pagination.pageSize
          } else {
            if (sorter.field) {
              this.search.sort = `${sorter.field}-${sorter.order == 'descend' ? 'asc' : 'desc'}`
            } else {
              const $search = this.search
              $search.sort && delete $search.sort
              this.search = { ...$search }
            }
            if (JSON.stringify(filters) !== '{}') {
              this.search.pageNo = 1
              for (const filterkey in filters) { this.search[filterkey] = filters[filterkey].toString() }
            }
            if (this.search.pageNo !== pagination.current) {
              this.search.pageNo = pagination.current
            } else {
              this.search.pageNo = 1
            }
          }
          this.getTableList()
        },
        pageChange (page, pageSize) {
          this.pageOption.current = page
          this.search.pageNo = page
          this.getTableList()
        },
        pageSizeChange (current, size) {
          this.search.pageSize = size
          this.search.pageNo = 1
          this.getTableList()
        }
      }
}